| label | variable | distribution | lower | upper |
|---|---|---|---|---|
| Seedling Cost Rice (IDR) | seedling_cost_rice | posnorm | 120000.00 | 900000.0 |
| Planting Cost Rice (IDR) | planting_cost_rice | posnorm | 60000.00 | 900000.0 |
| Herbicide Cost Rice (IDR) | herbicide_cost_rice | posnorm | 100000.00 | 400000.0 |
| Plowing Cost Rice (IDR) | plowing_cost_rice | posnorm | 500000.00 | 750000.0 |
| Dolomite Cost Rice (IDR) | dolomite_cost_rice | posnorm | 60000.00 | 375000.0 |
| Land Clearing Rice Cost (IDR) | clearing_cost_rice | posnorm | 120000.00 | 600000.0 |
| Equipment cost 3 years replacement (IDR) | equipment_cost_rice_3 | posnorm | 290000.00 | 550000.0 |
| Equipment cost 5 years replacement (IDR) | equipment_cost_rice_5 | posnorm | 720000.00 | 910000.0 |
| Insecticide Cost Rice (IDR) | insecticide_cost_rice | posnorm | 75000.00 | 250000.0 |
| Spraying Cost Rice (IDR) | spraying_cost_rice | posnorm | 60000.00 | 200000.0 |
| Fertilizer Cost (IDR) | fertilizer_cost_rice | posnorm | 650000.00 | 4250000.0 |
| Fertilizing Cost Rice (IDR) | fertilizing_cost_rice | posnorm | 120000.00 | 600000.0 |
| Harvesting Cost Rice (IDR) | harvesting_cost_rice | posnorm | 70000.00 | 600000.0 |
| Packaging Cost Rice (IDR) | packaging_cost_rice | posnorm | 200000.00 | 300000.0 |
| Milling cost rice (IDR) | milling_cost_rice | posnorm | 900000.00 | 1800000.0 |
| Rice Production (Kg) | rice_production | posnorm | 1000.00 | 2000.0 |
| Rice Price (IDR) | rice_price | posnorm | 7000.00 | 9000.0 |
| Rice Benefit (IDR) | rice_benefit | posnorm | 3500000.00 | 18000000.0 |
| Life spans (Years) | n_years | const | 25.00 | 25.0 |
| Discount rate (%) | discount_rate | posnorm | 4.00 | 15.0 |
| Percentage Rice Risk Occur (%) | p_rice_risk_occur | tnorm_0_1 | 0.20 | 0.6 |
| Percentage Rice Yield Loss (%) | p_rice_yield_loss | posnorm | 0.10 | 1.0 |
| Transportation cost for monitoring (IDR) | transportation_cost | posnorm | 240000.00 | 360000.0 |
| Planting Cost Rubber (IDR) | planting_cost_rubber | posnorm | 400000.00 | 2250000.0 |
| Field Protection (IDR) | field_protection_rice | posnorm | 3140000.00 | 4400000.0 |
| Dike Construction for rice (IDR) | dike_construction_rice | posnorm | 24000000.00 | 32000000.0 |
| Percentage Coconut Risk Occur (%) | p_coco_risk_occur | tnorm_0_1 | 0.10 | 0.5 |
| Percentage Coconut Yield Loss (%) | p_coco_yield_loss | posnorm | 0.30 | 0.7 |
| Time To reach Immature Coconut (Years) | immature_coco_est | const | 4.00 | 4.0 |
| Time To reach Mature Coconut (Years) | mature_coco_est | const | 8.00 | 8.0 |
| Maximum Coconut Estimation Yield (Kg) | max_coco_harvest | posnorm | 1500.00 | 1620.0 |
| Coconut production (Kg) | coco_yield | posnorm | 4000.00 | 4950.0 |
| Seedling Cost Coconut (IDR) | seedling_cost_coco | posnorm | 400000.00 | 900000.0 |
| Coconut price (Rp/Pcs) | coco_price | posnorm | 1000.00 | 5000.0 |
| Percentation Immature Yield Coconut (%) | immature_coco_yield_est | posnorm | 20.00 | 50.0 |
| Percentation Mature Yield Coconut (%) | mature_coco_yield_est | posnorm | 60.00 | 80.0 |
| Planting Cost Coconut (IDR) | planting_cost_coco | posnorm | 300000.00 | 900000.0 |
| Fertilizer Cost Coconut before first harvesting (IDR) | fertilizer_cost_coco_pre | posnorm | 12000.00 | 75000.0 |
| Fertilizer Cost Coconut after first harvesting (IDR) | fertilizer_cost_coco_post | posnorm | 28000.00 | 100000.0 |
| Harvesting Cost Coconut (IDR) | harvesting_cost_coco | posnorm | 2400000.00 | 5400000.0 |
| Percentage Areca (Pinang) Risk Occur (%) | p_pinang_risk_occur | tnorm_0_1 | 0.10 | 0.5 |
| Percentage Areca (Pinang) Yield Loss (%) | p_pinang_yield_loss | posnorm | 0.20 | 0.7 |
| Time To reach Immature (First Yield) Areca (Pinang) (Years) | immature_pn_est | const | 3.00 | 3.0 |
| Time To reach Mature Areca (Pinang) (Years) | mature_pn_est | const | 6.00 | 6.0 |
| Maximum Areca (Pinang) Estimation Yield (Kg) | max_pn_harvest | posnorm | 360.00 | 400.0 |
| Areca (Pinang) production (kg) | pinang_yield | posnorm | 360.00 | 400.0 |
| Seedling Cost Areca (IDR) | seedling_cost_pinang | posnorm | 108000.00 | 200000.0 |
| Areca (Pinang) price (IDR) | pinang_price | posnorm | 10000.00 | 15000.0 |
| Percentation Immature Yield Areca (Pinang) (%) | immature_pn_yield_est | posnorm | 40.00 | 60.0 |
| Percentation Mature Yield Areca (Pinang) (%) | mature_pn_yield_est | posnorm | 70.00 | 80.0 |
| Seedling Cost Areca (Pinang) Mono (IDR) | seedling_cost_png | posnorm | 375000.00 | 675000.0 |
| Planting Cost Areca (Pinang) (IDR) | planting_cost_png | posnorm | 300000.00 | 900000.0 |
| Fertilizer Cost Areca (Pinang) before first harvesting (IDR) | fertilizer_cost_png_pre | posnorm | 30000.00 | 225000.0 |
| Fertilizer Cost Areca (Pinang) Mono after first harvesting (IDR) | fertilizer_cost_png_post | posnorm | 70000.00 | 300000.0 |
| Harvesting Cost Areca (Pinang) (IDR) | harvesting_cost_png | posnorm | 1200000.00 | 3600000.0 |
| Areca (Pinang) Production (Kg) | png_yield | posnorm | 1250.00 | 1350.0 |
| Maximum Areca (Pinang) Estimation Yield (Kg) | max_png_harvest | posnorm | 1250.00 | 1350.0 |
| Planting Cost Rice (IDR) | planting_cost_rice_nfl | posnorm | 60000.00 | 600000.0 |
| Fertilizing Cost Rice (IDR) | fertilizing_cost_rice_nfl | posnorm | 60000.00 | 400000.0 |
| Fertilizing Cost Coconut Areca (IDR) | fertilizing_cost_coco_pinang | posnorm | 60000.00 | 100000.0 |
| Fertilizing Cost Areca (Pinang) (IDR) | fertilizing_cost_png | posnorm | 60000.00 | 100000.0 |
| Land Clearing Rice Cost (IDR) | clearing_cost_rice_nfl | posnorm | 120000.00 | 400000.0 |
| Maize Yield (Kg) | maize_yield | posnorm | 300.00 | 500.0 |
| Maize Price per Kg (IDR) | maize_price | posnorm | 3500.00 | 4500.0 |
| Planting, Harvesting and Fertilizer Cost for Maize (IDR) | maize_cost | posnorm | 530000.00 | 1100000.0 |
| Decay Rate Maize (%) | decay_rate_maize | posnorm | 0.05 | 0.1 |
| Percentage Risk Maize Occur (%) | p_maize_risk_occur | tnorm_0_1 | 0.20 | 0.6 |
| Percentage Yield Loss Maize (%) | p_maize_yield_loss | posnorm | 0.10 | 1.0 |
| Cost Variation | CV_cost | posnorm | 10.00 | 20.0 |
| Areca Price Variation | CV_areca_price | posnorm | 10.00 | 40.0 |
| Maize Price Variation | CV_maize_price | posnorm | 10.00 | 30.0 |
| Rice Price Variation | CV_rice_price | posnorm | 10.00 | 30.0 |
| Coconut Price Variation | CV_coco_price | posnorm | 10.00 | 30.0 |
| Risk Variation | CV_risk | posnorm | 2.00 | 12.0 |
| CV Variation | var_CV | posnorm | 20.00 | 50.0 |
| IDR to USD | cur_change | const | 15141.30 | 15141.3 |
library(decisionSupport)
first_decision_function <- function(x, varnames) {
# Corresponding to 25 years of simulation
n_years <- 25
# Define each variable as vectors of 25 values
# Cost variables
seedling.cost.rice <- rep(0, n_years)
land.clearing.rice <- rep(0, n_years)
herbicide.cost.rice <- rep(0, n_years)
fertilizer.cost.rice <- rep(0, n_years)
fertilizing.cost.rice <- rep(0, n_years)
spraying.cost.rice <- rep(0, n_years)
dolomite.cost.rice <- rep(0, n_years)
insecticide.cost.rice <- rep(0, n_years)
milling.cost.rice <- rep(0, n_years)
packaging.cost.rice <- rep(0, n_years)
plowing.cost.rice <- rep(0, n_years)
planting.cost.rice <- rep(0, n_years)
harvest.cost.rice <- rep(0, n_years)
equipment.cost.rice <- rep(0, n_years)
equipment.cost.rice.5 <- rep(0, n_years)
equipment.cost.rice.3 <- rep(0, n_years)
dike.cost.rice <- rep(0, n_years)
field.protection.rice <- rep(0, n_years)
# Cost variables coco-areca nut (pinang)
seedling.cost.coco <- rep(0, n_years)
planting.cost.coco <- rep(0, n_years)
harvesting.cost.coco.pn <- rep(0, n_years)
fertilizing.cost.coco.pn <- rep(0, n_years)
fertilizer.cost.coco <- rep(0, n_years)
seedling.cost.pn <- rep(0, n_years)
harvesting.cost.coco.pn <- rep(0, n_years)
# Benefit variables Coco-areca nut
yield.coco.risk <- rep(0, n_years)
yield.rice.risk <- rep(0, n_years)
pn_yield <- rep(0, n_years)
pn.price <- rep(0, n_years)
yield.pinang.risk <- rep(0, n_years)
total_rice_benefit <- rep(0, n_years)
coco.yield <- rep(0, n_years)
coco.price <- rep(0, n_years)
# Simulate the chance for risk events to occur during the simulation period
coco.risk <- chance_event(chance = p_coco_risk_occur, value_if = 1, n_years)
pinang.risk <- chance_event(chance = p_pinang_risk_occur, value_if = 1, n_years)
rice.risk <- chance_event(chance = p_rice_risk_occur, value_if = 1, n_years)
maize.risk <- chance_event(chance = p_maize_risk_occur, value_if = 1, n = n_years)
pinang.risk[1:n_years] <- vv(p_pinang_risk_occur, CV_risk, n_years)
coco.risk[1:n_years] <- vv(p_coco_risk_occur, CV_risk, n_years)
rice.risk[1:n_years] <- vv(p_rice_risk_occur, CV_risk, n_years)
yield.coco.risk[1:n_years] <- vv(p_coco_yield_loss, CV_risk, n_years)
yield.pinang.risk[1:n_years] <- vv(p_pinang_yield_loss, CV_risk, n_years)
yield.rice.risk[1:n_years] <- vv(p_rice_yield_loss, CV_risk, n_years)
### Calculate system cost of Rice
# Seedling cost rice
seedling.cost.rice[1:n_years] <- vv(seedling_cost_rice, CV_cost, n_years)
# Land clearing rice
land.clearing.rice[1:n_years] <- vv(clearing_cost_rice, CV_cost, n_years)
# Herbicide cost rice
herbicide.cost.rice[1:n_years] <- vv(herbicide_cost_rice, CV_cost, n_years)
# Fertilizer cost rice
fertilizer.cost.rice[1:n_years] <- vv(fertilizer_cost_rice, CV_cost, n_years)
# Fertilizing cost rice
fertilizing.cost.rice[1:n_years] <- vv(fertilizing_cost_rice, CV_cost, n_years)
# Spraying insecticide cost rice
spraying.cost.rice[1:n_years] <- vv(spraying_cost_rice, CV_cost, n_years)
# Planting cost rice
planting.cost.rice[1:n_years] <- vv(planting_cost_rice, CV_cost, n_years)
# Plowing cost rice
plowing.cost.rice[1:n_years] <- vv(plowing_cost_rice, CV_cost, n_years)
# Land management Rice
dolomite.cost.rice[1:n_years] <- vv(dolomite_cost_rice, CV_cost, n_years)
# Spraying insecticide cost rice
insecticide.cost.rice[1:n_years] <- vv(insecticide_cost_rice, CV_cost, n_years)
# Milling cost rice
milling.cost.rice[1:n_years] <- vv(milling_cost_rice, CV_cost, n_years)
# Packaging Cost rice
packaging.cost.rice[1:n_years] <- vv(packaging_cost_rice, CV_cost, n_years)
# Harvesting cost
harvest.cost.rice[1:n_years] <- vv(harvesting_cost_rice, CV_cost, n_years)
# Dike cost
dike.cost.rice[1] <- vv(dike_construction_rice, CV_cost, 1)
dike.cost.rice[2:n_years] <- 0
# Field Protection cost using barbed wire
field.protection.rice[1] <- vv(field_protection_rice, CV_cost, 1)
field.protection.rice[2:9] <- 0
field.protection.rice[10] <- vv(field_protection_rice/2, CV_cost, 1)
field.protection.rice[11:19] <- 0
field.protection.rice[20] <- vv(field_protection_rice/2, CV_cost, 1)
field.protection.rice[21:n_years] <- 0
# Equipment cost 3 years replacement
equipment.cost.rice.3[1] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[2:3] <- 0
equipment.cost.rice.3[5] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[6:8] <- 0
equipment.cost.rice.3[9] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[10:12] <- 0
equipment.cost.rice.3[13] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[14:16] <- 0
equipment.cost.rice.3[17] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[18:20] <- 0
equipment.cost.rice.3[21] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[22:24] <- 0
equipment.cost.rice.3[25] <- vv(equipment_cost_rice_3, CV_cost, 1)
# Equipment cost 5 years replacement
equipment.cost.rice.5[1] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[2:6] <- 0
equipment.cost.rice.5[7] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[8:12] <- 0
equipment.cost.rice.5[13] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[14:18] <- 0
equipment.cost.rice.5[19] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[20:24] <- 0
equipment.cost.rice.5[25] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice <- equipment.cost.rice.5 + equipment.cost.rice.3
# Calculate system benefit of Rice
rice.yield.risk <- vv(rice_production*(1-rice.risk*yield.rice.risk), CV_risk, n_years)
tot_rice_benefit <- vv(rice.yield.risk * rice_price, CV_rice_price, n_years)
# Calculate NPV of rice
# Total Benefit Rice (Family Labour and Non Family Labour are included using shadow price)
total_rice_benefit <- ((tot_rice_benefit - seedling.cost.rice - land.clearing.rice -
herbicide.cost.rice - fertilizer.cost.rice - harvest.cost.rice -
planting.cost.rice - plowing.cost.rice - equipment.cost.rice -
dolomite.cost.rice - insecticide.cost.rice - milling.cost.rice -
packaging.cost.rice - fertilizing.cost.rice - spraying.cost.rice - field.protection.rice)*2)/cur_change
# Calculate rice agroforestry
# Coco yield
seedling.cost.coco[1] <- vv(seedling_cost_coco, CV_cost, 1)
seedling.cost.coco[2:n_years] <- 0
# Fertilizer cost coco
fertilizer.cost.coco[1:4] <- vv(fertilizer_cost_coco_pre, CV_cost, 4)
fertilizer.cost.coco[5:n_years] <- vv(fertilizer_cost_coco_post, CV_cost, n_years - 4)
# Fertilizing cost coco pinang
fertilizing.cost.coco.pn[1:4] <- vv(fertilizing_cost_coco_pinang, CV_cost, 4)
fertilizing.cost.coco.pn[5:n_years] <- vv(fertilizing_cost_coco_pinang, CV_cost, n_years - 4)
# Planting cost coco
planting.cost.coco[1] <- vv(planting_cost_coco, CV_cost, 1)
planting.cost.coco[2:n_years] <- 0
# Harvesting cost coco pinang
harvesting.cost.coco.pn[1:3] <- 0
harvesting.cost.coco.pn[4:n_years] <- vv(harvesting_cost_coco, CV_cost, n_years - 3)
# Coco Price
coco.price[1:n_years] <- vv(coco_price, CV_coco_price, n_years)
cc_yield <- gompertz_yield(max_harvest = max_coco_harvest,
time_to_first_yield_estimate = immature_coco_est,
time_to_second_yield_estimate = mature_coco_est,
first_yield_estimate_percent = immature_coco_yield_est,
second_yield_estimate_percent = mature_coco_yield_est,
n_years = n_years,
var_CV = 0,
no_yield_before_first_estimate = TRUE)
cc_yield_risk <- cc_yield*(1-coco.risk*yield.coco.risk)
tot_cc_benefit <- cc_yield_risk * coco.price
# Calculate Pinang System
# seedling cost pinang
seedling.cost.pn[1] <- vv(seedling_cost_pinang, CV_cost, 1)
seedling.cost.pn[2:n_years] <- 0
# Pinang Price
pn.price[1:n_years] <- vv(pinang_price, CV_areca_price, n_years)
# pinang yield
pn_yield <- gompertz_yield(max_harvest = max_pn_harvest,
time_to_first_yield_estimate = immature_pn_est,
time_to_second_yield_estimate = mature_pn_est,
first_yield_estimate_percent = immature_pn_yield_est,
second_yield_estimate_percent = mature_pn_yield_est,
n_years = n_years,
var_CV = 0,
no_yield_before_first_estimate = TRUE)
pn_yield_risk <- pn_yield*(1-pinang.risk*yield.pinang.risk)
tot_pn_benefit <- pn_yield_risk * pn.price
# Maize along the dike
time <- 1:n_years
decay_speed_maize <- -log(1-decay_rate_maize)
AF_maize <- maize_yield*exp(-decay_speed_maize*(time-1))
tot_AF_maize <- vv(maize_yield*(1-maize.risk*p_rice_yield_loss), CV_risk, n_years)
AF_maize_revenue <- (tot_AF_maize*vv(maize_price, CV_maize_price, n_years))
AF_maize_costs <- vv(maize_cost, CV_cost, n_years)
AF_maize_benefit <- (AF_maize_revenue-AF_maize_costs)*2
# Calculate NPV of rice agro forestry (coco pinang)
# Total Benefit Coco-areca nut (Family Labour and Non Family Labour are included using shadow price)
total_rice_ccpn_benefit <- ((total_rice_benefit + tot_cc_benefit + tot_pn_benefit + AF_maize_benefit) -
seedling.cost.coco - dike.cost.rice - field.protection.rice -
planting.cost.coco - harvesting.cost.coco.pn - fertilizer.cost.coco
- seedling.cost.pn - fertilizing.cost.coco.pn)/cur_change
# NPV comparison
# NPV Rice- Coco-areca nut (Family Labour and Non Family Labour are included using shadow price)
NPV_rice_ccpn <- discount(total_rice_ccpn_benefit, discount_rate = discount_rate, calculate_NPV = TRUE)
# NPV Rice (Family Labour and Non Family Labour are included using shadow price)
NPV_rice <- discount(total_rice_benefit, discount_rate = discount_rate, calculate_NPV = TRUE)
# Benefit of choosing rice Coco-areca nut with dike over Rice Mono without dike
tradeoff_benefit <- NPV_rice_ccpn - NPV_rice
# Final NPV of the decision to choose Rice-Coco-areca nut with dike and field protection over Rice Mono
NPV_tradeoff <- discount(tradeoff_benefit, discount_rate = discount_rate, calculate_NPV = TRUE)
# In the return list, one can indicate any outcome they wish to see from the model
return(list(trade_off = NPV_tradeoff,
rice_ccpn_NPV = NPV_rice_ccpn,
rice_NPV = NPV_rice,
Cash_Flow_Rice = total_rice_benefit,
Cash_Flow_Rice_Pinang_Coco = total_rice_ccpn_benefit))
}
library(decisionSupport)
second_decision_function <- function(x, varnames) {
# Corresponding to 25 years of simulation
n_years <- 25
# Define each variable as vectors of 25 values
# Cost variables rice
seedling.cost.rice <- rep(0, n_years)
land.clearing.rice <- rep(0, n_years)
herbicide.cost.rice <- rep(0, n_years)
fertilizer.cost.rice <- rep(0, n_years)
fertilizing.cost.rice <- rep(0, n_years)
spraying.cost.rice <- rep(0, n_years)
dolomite.cost.rice <- rep(0, n_years)
insecticide.cost.rice <- rep(0, n_years)
milling.cost.rice <- rep(0, n_years)
packaging.cost.rice <- rep(0, n_years)
plowing.cost.rice <- rep(0, n_years)
planting.cost.rice <- rep(0, n_years)
harvest.cost.rice <- rep(0, n_years)
equipment.cost.rice <- rep(0, n_years)
equipment.cost.rice.5 <- rep(0, n_years)
equipment.cost.rice.3 <- rep(0, n_years)
dike.cost.rice <- rep(0, n_years)
field.protection.rice <- rep(0, n_years)
# Benefit variables
total_rice_benefit <- rep(0, n_years)
yield.rice.risk <- rep(0, n_years)
# Cost variable areca nut (pinang)
seedling.cost.png <- rep(0, n_years)
planting.cost.png <- rep(0, n_years)
harvesting.cost.png <- rep(0, n_years)
fertilizing.cost.png <- rep(0, n_years)
fertilizer.cost.png <- rep(0, n_years)
# Benefit variables areca nut c (Pinang)
png_yield <- rep(0, n_years)
pn.price <- rep(0, n_years)
yield.pinang.risk <- rep(0, n_years)
# Simulate the chance for risk events to occur during the simulation period
pinang.risk <- chance_event(chance = p_pinang_risk_occur, value_if = 1, n_years)
rice.risk <- chance_event(chance = p_rice_risk_occur, value_if = 1, n_years)
maize.risk <- chance_event(chance = p_maize_risk_occur, value_if = 1, n = n_years)
pinang.risk[1:n_years] <- vv(p_pinang_risk_occur, CV_risk, n_years)
rice.risk[1:n_years] <- vv(p_rice_risk_occur, CV_risk, n_years)
yield.pinang.risk[1:n_years] <- vv(p_pinang_yield_loss, CV_risk, n_years)
yield.rice.risk[1:n_years] <- vv(p_rice_yield_loss, CV_risk, n_years)
### Calculate system cost of Rice
# Seedling cost rice
seedling.cost.rice[1:n_years] <- vv(seedling_cost_rice, CV_cost, n_years)
# Land clearing rice
land.clearing.rice[1:n_years] <- vv(clearing_cost_rice, CV_cost, n_years)
# Herbicide cost rice
herbicide.cost.rice[1:n_years] <- vv(herbicide_cost_rice, CV_cost, n_years)
# Fertilizer cost rice
fertilizer.cost.rice[1:n_years] <- vv(fertilizer_cost_rice, CV_cost, n_years)
# Fertilizing cost rice
fertilizing.cost.rice[1:n_years] <- vv(fertilizing_cost_rice, CV_cost, n_years)
# Spraying cost rice
spraying.cost.rice[1:n_years] <- vv(spraying_cost_rice, CV_cost, n_years)
# Planting cost rice
planting.cost.rice[1:n_years] <- vv(planting_cost_rice, CV_cost, n_years)
# Plowing cost rice
plowing.cost.rice[1:n_years] <- vv(plowing_cost_rice, CV_cost, n_years)
# Land management Rice
dolomite.cost.rice[1:n_years] <- vv(dolomite_cost_rice, CV_cost, n_years)
# Spraying insecticide cost rice
insecticide.cost.rice[1:n_years] <- vv(insecticide_cost_rice, CV_cost, n_years)
# Milling cost rice
milling.cost.rice[1:n_years] <- vv(milling_cost_rice, CV_cost, n_years)
# Packaging Cost rice
packaging.cost.rice[1:n_years] <- vv(packaging_cost_rice, CV_cost, n_years)
# Harvesting cost
harvest.cost.rice[1:n_years] <- vv(harvesting_cost_rice, CV_cost, n_years)
# Dike cost
dike.cost.rice[1] <- vv(dike_construction_rice, CV_cost, 1)
dike.cost.rice[2:n_years] <- 0
# Field Protection cost
field.protection.rice[1] <- vv(field_protection_rice, CV_cost, 1)
field.protection.rice[2:9] <- 0
field.protection.rice[10] <- vv(field_protection_rice/2, CV_cost, 1)
field.protection.rice[11:19] <- 0
field.protection.rice[20] <- vv(field_protection_rice/2, CV_cost, 1)
field.protection.rice[21:n_years] <- 0
# Equipment cost 3 years replacement
equipment.cost.rice.3[1] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[2:3] <- 0
equipment.cost.rice.3[5] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[6:8] <- 0
equipment.cost.rice.3[9] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[10:12] <- 0
equipment.cost.rice.3[13] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[14:16] <- 0
equipment.cost.rice.3[17] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[18:20] <- 0
equipment.cost.rice.3[21] <- vv(equipment_cost_rice_3, CV_cost, 1)
equipment.cost.rice.3[22:24] <- 0
equipment.cost.rice.3[25] <- vv(equipment_cost_rice_3, CV_cost, 1)
# Equipment cost 5 years replacement
equipment.cost.rice.5[1] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[2:6] <- 0
equipment.cost.rice.5[7] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[8:12] <- 0
equipment.cost.rice.5[13] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[14:18] <- 0
equipment.cost.rice.5[19] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice.5[20:24] <- 0
equipment.cost.rice.5[25] <- vv(equipment_cost_rice_5, CV_cost, 1)
equipment.cost.rice <- equipment.cost.rice.5 + equipment.cost.rice.3
# Calculate system benefit of Rice
rice.yield.risk <- vv(rice_production*(1-rice.risk*yield.rice.risk), CV_risk, n_years)
tot_rice_benefit <- vv(rice.yield.risk * rice_price, CV_rice_price, n_years)
# Calculate NPV of rice
# Total Benefit Rice (Family Labour and Non Family Labour are included using shadow price)
total_rice_benefit <- ((tot_rice_benefit - seedling.cost.rice - land.clearing.rice -
herbicide.cost.rice - fertilizer.cost.rice - harvest.cost.rice -
planting.cost.rice - plowing.cost.rice - equipment.cost.rice -
dolomite.cost.rice - insecticide.cost.rice - milling.cost.rice -
packaging.cost.rice - fertilizing.cost.rice - spraying.cost.rice - field.protection.rice)*2)/cur_change
# Calculate rice agroforestry
# Pinang cost
seedling.cost.png[1] <- vv(seedling_cost_png, CV_cost, 1)
seedling.cost.png[2:n_years] <- 0
# Fertilizer cost pinang
fertilizer.cost.png[1:3] <- vv(fertilizer_cost_png_pre, CV_cost, 3)
fertilizer.cost.png[4:n_years] <- vv(fertilizer_cost_png_post, CV_cost, n_years - 3)
# Fertilizing cost pinang
fertilizing.cost.png[1:3] <- vv(fertilizing_cost_png, CV_cost, 3)
fertilizing.cost.png[4:n_years] <- vv(fertilizing_cost_png, CV_cost, n_years - 3)
# Planting cost pinang
planting.cost.png[1] <- vv(planting_cost_png, CV_cost, 1)
planting.cost.png[2:n_years] <- 0
# Harvesting cost Areca nut
harvesting.cost.png[1:3] <- 0
harvesting.cost.png[4:n_years] <- vv(harvesting_cost_png, CV_cost, n_years - 3)
# Areca nut Price
pn.price[1:n_years] <- vv(pinang_price, CV_cost, n_years)
png_yield <- gompertz_yield(max_harvest = max_png_harvest,
time_to_first_yield_estimate = immature_pn_est,
time_to_second_yield_estimate = mature_pn_est,
first_yield_estimate_percent = immature_pn_yield_est,
second_yield_estimate_percent = mature_pn_yield_est,
n_years = n_years,
var_CV = 0,
no_yield_before_first_estimate = TRUE)
png_yield_risk <- png_yield*(1-pinang.risk*yield.pinang.risk)
tot_png_benefit <- png_yield_risk * pn.price
time <- 1:n_years
decay_speed_maize <- -log(1-decay_rate_maize)
AF_maize <- maize_yield*exp(-decay_speed_maize*(time-1))
tot_AF_maize <- vv(maize_yield*(1-maize.risk*p_rice_yield_loss), CV_risk, n_years)
AF_maize_revenue <- (tot_AF_maize*vv(maize_price, CV_maize_price, n_years))
AF_maize_costs <- vv(maize_cost, CV_cost, n_years)
AF_maize_benefit <- (AF_maize_revenue-AF_maize_costs)*2
# Calculate NPV of rice agro forestry
# Total Benefit Rice-areca nut (Family Labour and Non Family Labour are included using shadow price)
total_rice_pn_benefit <- (total_rice_benefit + tot_png_benefit + AF_maize_benefit - dike.cost.rice -
field.protection.rice - planting.cost.png - harvesting.cost.png - fertilizer.cost.png -
seedling.cost.png - fertilizing.cost.png)/cur_change
# NPV comparison
# NPV Rice-Areca nut (Family Labour and Non Family Labour are included using shadow price)
NPV_rice_pn <- discount(total_rice_pn_benefit,
discount_rate = discount_rate, calculate_NPV = TRUE)
# NPV Rice (Family Labour and Non Family Labour are included using shadow price)
NPV_rice <- discount(total_rice_benefit,
discount_rate = discount_rate, calculate_NPV = TRUE)
# Benefit of choosing rice pinang with dike over rice without dike
# Benefit of choosing rice-areca nut with dike over Rice Mono without dike
tradeoff_benefit <- NPV_rice_pn - NPV_rice
# Final NPV of the decision to choose Rice-Areca over Rice Mono
# Final NPV of the decision to choose Rice-Areca with dike and field protection over Rice Mono
NPV_tradeoff <- discount(tradeoff_benefit,
discount_rate = discount_rate, calculate_NPV = TRUE)
# In the return list, one can indicate any outcome they wish to see from the model
return(list(trade_off = NPV_tradeoff,
rice_pn_NPV = NPV_rice_pn,
rice_NPV = NPV_rice,
Cash_Flow_Rice = total_rice_benefit,
Cash_Flow_Rice_Pinang = total_rice_pn_benefit))
}
After the model function has been created, it is continued to the function “mCSimulation” from the decision Support Package. The simulation is run a total of 10000 times.
library(decisionSupport)
# Read the estimates from the CSV file
estimate <- estimate_read_csv("Rice_coco_pinang_dike - fix - Copy.csv")
# Perform the Monte Carlo simulation 1
mcSimulation_result1 <- mcSimulation(estimate = estimate,
model_function = first_decision_function,
numberOfModelRuns = 10000,
functionSyntax = "plainNames")
# Perform the Monte Carlo simulation 2
mcSimulation_result2 <- mcSimulation(estimate = estimate,
model_function = second_decision_function,
numberOfModelRuns = 10000,
functionSyntax = "plainNames")
plot_cashflow(mcSimulation_object = mcSimulation_result1,
color_25_75 = "darkolivegreen4",
color_5_95 = "darkolivegreen1",
color_median = "blue",
cashflow_var_name = "Cash_Flow_Rice_Pinang_Coco")
Graph. 1 Cashflow Rice-Coco-areca nut